Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald\include\herald\data\contact_log.h
Line
Count
Source
1
//  Copyright 2020-2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#ifndef HERALD_CONTACT_LOG_H
6
#define HERALD_CONTACT_LOG_H
7
8
#include "../sensor_delegate.h"
9
#include "payload_data_formatter.h"
10
#include "sensor_logger.h"
11
#include "../context.h"
12
13
namespace herald::data {
14
15
/**
16
 * Logs all contact info to STDERR to allow it to be extracted as a stream
17
 */
18
template <typename ContextT, typename PayloadDataFormatterT>
19
class ErrorStreamContactLogger {
20
public:
21
  ErrorStreamContactLogger(ContextT& context, PayloadDataFormatterT& formatter)
22
    : ctx(context), 
23
      fmt(formatter)
24
      HLOGGERINIT(ctx,"Sensor","contacts.log")
25
1
  {
26
1
    ;
27
1
  }
28
1
  ~ErrorStreamContactLogger() = default;
29
30
  // Sensor delegate overrides
31
1
  void sensor(SensorType sensor, const TargetIdentifier& didDetect) {
32
1
    HTDBG("didDetect");
33
1
  }
34
  // TODO Log all the other activity
35
  // void sensor(SensorType sensor, const PayloadData& didRead, const TargetIdentifier& fromTarget) {}
36
  // void sensor(SensorType sensor, const ImmediateSendData& didReceive, const TargetIdentifier& fromTarget) {}
37
  // void sensor(SensorType sensor, const std::vector<PayloadData>& didShare, const TargetIdentifier& fromTarget){}
38
  // void sensor(SensorType sensor, const Proximity& didMeasure, const TargetIdentifier& fromTarget) {}
39
  // template <typename LocationT>
40
  // void sensor(SensorType sensor, const Location<LocationT>& didVisit) {}
41
  // void sensor(SensorType sensor, const Proximity& didMeasure, const TargetIdentifier& fromTarget, const PayloadData& withPayload) {}
42
  // void sensor(SensorType sensor, const SensorState& didUpdateState) {}
43
44
private:
45
  std::string csv(std::string toEscape) const noexcept {
46
    // C++23 only: if (toEscape.contains(",") || toEscape.contains("\"") || toEscape.contains("'") || toEscape.contains("’")) {
47
    // Pre C++23:-
48
    if (std::string::npos != toEscape.find(",") || 
49
        std::string::npos != toEscape.find("\"") || 
50
        std::string::npos != toEscape.find("'") || 
51
        std::string::npos != toEscape.find("’")) {
52
      return "\"" + toEscape + "\"";
53
    }
54
    return toEscape;
55
  }
56
57
  std::string timestamp() const noexcept {
58
    return Date().iso8601DateTime();
59
  }
60
61
  ContextT& ctx;
62
  PayloadDataFormatterT& fmt;
63
64
  HLOGGER(ContextT);
65
};
66
67
}
68
69
#endif